package com.cwvs.cat.adapter;

import java.util.List;

import com.cwvs.cat.OrderActivity;
import com.cwvs.cat.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class OrderGvAdapter extends BaseAdapter {
	
	private Context context;
	
	private List<String> list;
	
	private LayoutInflater mInflater;
	
	public OrderGvAdapter(Context context, List<String> list) {
		this.context = context;
        this.list = list;
        this.mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.gridview_order_item, null);
            holder = new ViewHolder();
            holder.fl = (FrameLayout) convertView.findViewById(R.id.fl);
            holder.tvMenu = (TextView) convertView.findViewById(R.id.tvMenu);
            holder.ivLine = (ImageView) convertView.findViewById(R.id.ivLine);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tvMenu.setText(list.get(position));
        
        if (OrderActivity.p == position) {
        	holder.tvMenu.setTextColor(context.getResources().getColor(R.color.gray_font));
			holder.ivLine.setVisibility(View.VISIBLE);
		} else {
			holder.tvMenu.setTextColor(context.getResources().getColor(R.color.gray_font));
			holder.ivLine.setVisibility(View.GONE);
		}

        return convertView;
	}
	
	public class ViewHolder {
        private FrameLayout fl;
        private ImageView ivLine;
        private TextView tvMenu;
    }

}
